package com.example.demo.mapper;

import com.example.demo.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    /**
     * 查询所有博客
     */
//    @Select("select id,title,content,user_id ,update_time" +
//            " from blog where delete_flag = 0 ")
//    public List<BlogInfo> selectAll();
    @Select("select id, title, content, user_id, update_time from `blog` where delete_flag=0  ")
    List<BlogInfo> selectAll();

    /**
     * 根据博客id 查询博客
     */
//    @Select("select id,title,content,user_id,update_time " +
//            " from blog where delete_flag = 0 and id = #{id}")

    @Select("select id, title, content, user_id, update_time" +
            " from `blog` where id = #{id} and delete_flag=0")
    public BlogInfo selectById(Integer id);


    /**
     * 插入博客
     */


    @Insert("insert into blog (title,content,user_id) " +
            " values (#{title},#{content},#{userId})")
    public Integer insertBlog(BlogInfo blogInfo);

    /**
     * 更新博客
     *
     */
    public Integer updateBlog(BlogInfo blogInfo);
}
